package ofmybatis.demo.transaction;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;

/**
 * 事务模板
 * @author zz
 *
 */

public class TransactionTemplateSupport {

	@Autowired
	private PlatformTransactionManager transactionManager;
	
	private TransactionTemplate requiredTransactionTemplate;
	
	protected TransactionTemplate getRequiresNewTransactionTemplate(){
		if (requiredTransactionTemplate == null){
			requiredTransactionTemplate = new TransactionTemplate(transactionManager);
			requiredTransactionTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRED);
		//	requiredTransactionTemplate.setReadOnly(true);
		//	requiredTransactionTemplate.setTimeout(30000);
		}
		
		return requiredTransactionTemplate;
	}

}
